package top.frsf.mqtt.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageType;
import lombok.RequiredArgsConstructor;
import top.frsf.mqtt.config.MqttHandlerContext;

@RequiredArgsConstructor
public class MqttServerHandler extends SimpleChannelInboundHandler<MqttMessage> {

    private final MqttHandlerContext mqttHandlerContext;

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MqttMessage msg) {
        // 获取消息处理策略，业务处理
        MqttMessageType messageType = msg.fixedHeader().messageType();
        mqttHandlerContext.getStrategy(messageType).handle(ctx, msg);
    }

}